#include <iostream>
using namespace std;
int main()
{
	int n,m,k;
	char s1[100],s2[100];
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>s1[i];
	cin>>m;
	for(int i=0;i<m;i++)
		cin>>s2[i];
	cin>>k;
		cout<<s1[k-1%n]<<" ";
		cout<<s2[k-1%m];
	return 0;
}